package exam.common.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * <p>MD5</p>
 * <p>Mã hóa mật khẩu MD5</p>
 * 
 * @author Phong
 * @version 06/05/2012
 */
public class MD5 {
	
	private final static String MD5 = "MD5";
	
	/**
	 * Mã hóa chuỗi text sang dạng MD5
	 * @param text
	 * @return
	 */
	public static String encryption(String text) {
		try {
			MessageDigest md5 = MessageDigest.getInstance(MD5);
			md5.update(text.getBytes());
			BigInteger dis = new BigInteger(1, md5.digest());
			text = dis.toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return text;
	}
}
